package com.mtw.bbs.common.core.util;

import org.apache.commons.lang3.StringUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 公共工具
 */
public class CommonUtil {


    /**
     * 生成md5
     */
    public static String getMD5(String str)  {
        if (StringUtils.isBlank(str)){
            return null;
        }
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte[] encryptionKey = md.digest();
            StringBuilder builder = new StringBuilder();
            for (byte b : encryptionKey) {
                builder.append(String.format("%02X",b));
            }
            return builder.toString();
        } catch (NoSuchAlgorithmException e) {
            return null;
        }

    }
}
